/**
*Extend Function
**/
var extend = function(origin, target){
  for (var property in target) {
    if (typeof target[property] === "object" && !isElement(target[property])) {
      origin[property] = origin[property] || {};
      arguments.callee(origin[property], target[property]);
    } else {
      origin[property] = target[property];
    }
  }
  return origin;
};
/**
*Object Serializer
**/
var serialize = function(xValue) {
	switch (typeof(xValue)) {
		case "undefined": return "void(0)";
		case "boolean":   return xValue.toString();
		case "number":    return xValue.toString();
		case "string":    return "\"" + JavaScriptStringEncode(xValue) + "\"";
		case "function":  return "eval(\"" + JavaScriptStringEncode(xValue.toString()) + "\")";
		case "object":
			if (xValue == null) return "null";
			var bArray = true;
			var asObjectValues = [], asArrayValues = [], iCounter = 0, iLength = null;
			for (var i in xValue) {
				if (bArray) switch (i) {
					case "length":
						// Part of an array but not stored, keep so we can check
						// if the length is correct
						break;
					case iCounter.toString():
						// Part of an array and stored, but he index must be sequential starting at 0.
						iCounter++;
						asArrayValues.push(serialize(xValue[i]));
						break;
					default:
						// Not an array
						bArray = false;
				}
				asObjectValues.push(serialize(i) + ":" + serialize(xValue[i]));
			}
			if (bArray) {
				try {
					bArray &= (xValue.length == iCounter);
				} catch (e) {
					bArray = false;
				}
			}
			return (bArray ?
				"[" + asArrayValues.join(",") + "]":
				"{" + asObjectValues.join(",") + "}"
			);
		default:
			throw new Error("Objects of type " + typeof(xValue) + " cannot be serialized.");
	}
}
//***********

function isElement(obj) {
  try {
      return obj instanceof HTMLElement;
  }
  catch(e){
    return (typeof obj==="object") &&
      (obj.nodeType===1) && (typeof obj.style === "object") &&
      (typeof obj.ownerDocument ==="object");
  }
}


function parseParamatrizedUrl(url, request){

	var parametrizedUrl = url;

	if(typeof request == 'string'){
		if(url.indexOf("?")-1 > 0){
			url = url.substring(0, url.indexOf("?")-1);	
		}

		if( request.indexOf("?") != 0){
			request = "?"+request;
		}	

		parametrizedUrl = url + request;
	}

	return parametrizedUrl;
}